package com.example.myworkers.controller;
/*
 *编写者：段光映
 */

import com.example.myworkers.model.Employee;
import com.example.myworkers.service.EmployeeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "Employee")
@RestController
@RequestMapping("/employee")
public class EmployeeController {
     @Autowired
     private EmployeeService employeeService;
     @ApiOperation(value = "添加方法")
    @PostMapping("/addEmployee")
    @CrossOrigin
    public int addEmployee(@RequestBody Employee employee){
         System.out.println("进入添加方法");
         return employeeService.insertEmployee(employee);
     }
     @ApiOperation(value = "删除方法")
     @GetMapping("/deleteEmpployee")
    public int deleteEmployee(int empno) {
         System.out.println("进入删除方法");
         int empvalue = 0;
         if (empno != 0) {
          Employee employee=new Employee();
          employee.setEmpno(empno);
          empvalue=employeeService.deleteEmployee(employee);
         }
         return empvalue;
     }
     @ApiOperation(value = "查找员工所有信息")
    @GetMapping("/getAll")
    public List<Employee> selectAllEmployee(Employee employee){
    System.out.println("进入查询所有员工信息方法");
    List<Employee> listemployee=employeeService.selectAllEmployee(employee);
    return listemployee;
     }
     @ApiOperation(value = "更新员工信息方法")
     @PutMapping("/UpdateEmployee")
     public int updateEployee(Employee employee){
         System.out.println("进入更新员工信息方法");
         return employeeService.updateEmployee(employee);
     }
     @ApiOperation(value = "对员工信息的单条查询方法")
    @GetMapping()
    public Employee getEmployee(int empno){
         Employee employee=new Employee();
         System.out.println("进入员工信息单条查询法");
         if (empno!=0){
             Employee employee1=new Employee();
             employee1.setEmpno(empno);
             employee=employeeService.selectEmployee(employee1);
         }
         return employee;
     }
}
